const orderModel = require("../models/order_model")

const Result = require("../beans/result")
// 查询订单
function getuserorder(userid, callback) {
    orderModel.getOrderList(userid, (err, data) => {
        if (err) {
            callback(new Result(err, data, "查询订单数据失败", 401))
        } else {

            callback(new Result(null, data, "查询订单数据成功", 200))
        }
    })
}
// 添加订单
function userAddorder(userid, callback) {
    orderModel.getOrderList(userid, (err, data) => {
        if (err) {
            callback(new Result(err, data, "添加订单数据失败", 401))
        } else {

            callback(new Result(null, data, "添加订单数据成功", 200))
        }
    })
}
// 获取订单详情
function getorderdetail(orderNo, callback) {
    orderModel.getuserOrderList(orderNo, (err, data) => {
        if (err) {
            callback(new Result(err, data, "查询订单详情数据失败", 401))
        } else {

            callback(new Result(null, data, "查询订单详情数据成功", 200))
        }
    })
}

// 取消订单
function userdeleteorder(orderNo, callback) {
    orderModel.getOrderList(orderNo, (err, data) => {
        if (err) {
            callback(new Result(err, data, "取消订单数据失败", 401))
        } else {

            callback(new Result(null, data, "取消订单数据成功", 200))
        }
    })
}
// 提交订单
function payuserOrder(orderNo, callback) {
    orderModel.getuserOrderList(orderNo, (err, data) => {
        if (err) {
            callback(new Result(err, data, "提交订单数据失败", 401))
        } else {

            callback(new Result(null, data, "提交订单数据成功", 200))
        }
    })
}
// 搜索订单/查看订单
function searchuserOrder(orderNo, callback) {
    orderModel.getuserOrderList(orderNo, (err, data) => {
        if (err) {
            callback(new Result(err, data, "搜索订单数据失败", 401))
        } else {

            callback(new Result(null, data, "搜索订单数据成功", 200))
        }
    })
}
//后台修改订单
function putuserOrder(putlist, callback) {
    orderModel.putuserOrderList( putlist, (err, data) => {
        if (err) {
            callback(new Result(err, data, "修改订单数据失败", 401))
        } else {

            callback(new Result(null, data, "修改订单数据成功", 200))
        }
    })
}
module.exports = {
    getuserorder,
    userAddorder,
    getorderdetail,
    userdeleteorder,
    payuserOrder,
    searchuserOrder,

    putuserOrder
}